<template>
	<view style="padding: 20rpx;">
		<button @click="onSetTimeCall()">单次定时器</button>
		<button @click="onSetTimeCallz(name,pwd)">带参数定时器</button>
		<button @click="onSetTimeClear()" type="warn">取消定时器</button>
		<button @click="onIner()" type="primary">周期打印</button>
		<button @click="onSetClearIner()" type="warn">取消定时器</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'ljq',
				pwd:'876',
				timeoutId:null,
				count:0,
				
			}
		},
		methods: {
			onSetTimeCall(){
				console.log("onSetTimeCall()-->");
				// setTimeout(callback,ms,any[])[，延迟时间，形参]
				this.timeoutId=setTimeout(()=>{
					console.log("延时2秒才会打印");
				},2000)
				
			},
			onSetTimeCallz(name,pwd){
				console.log("onSetTimeCallz-->name:"+name+",pwd:"+pwd);
				setTimeout(()=>{
					console.log("传参数>name:"+name+",>pwd:"+pwd);
				},2000,name,pwd);
			},
			onSetTimeClear(){
				console.log("onSetTimeClear-->定时器被取消了:"+this.timeoutId);
				clearTimeout(this.timeoutId);
			},
			onInter(){
				this.interalID = setInterval(()=>{
					this.count++;
					console.log("周期打印 count:",this.count);
				},1000)
			},
			onSetClearIner(){
				console.log("onSetClearIner:",this.interalID);
				clearInterval(this.interalID)
			}
		}
	}
</script>

<style>
	button{
		margin: 30rpx;
	}
</style>
